package cn.yunhe.servlet;

import cn.yunhe.biz.AdminService;
import cn.yunhe.pojo.Admin;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/CheckNameServlet")
public class CheckNameServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       String adminName= request.getParameter("adminName");

        AdminService adminService=new AdminService();
        Admin admin =adminService.checkAdmin(adminName);

        response.setContentType("text/html:charset=UTF-8");
        PrintWriter out=response.getWriter();
        if (admin!=null){
            out.print("用户名已存在请重试");
        }else{
            out.print("用户名有效");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
